<template>
	<view class="container">
		<view v-for="(item,index) in curHoleData" :key="index" class="z-b-r white-bg u-padding-20 u-margin-bottom-20">
			<view class="lineHeight">孔号：{{ item.num }}</view>
			<view class="lineHeight">孔深：{{ item.deep | $_formattingMoney }}</view>
			<view class="u-flex u-row-between u-col-center lineHeight">
				<view class="">状态：{{ item.status == 1 ? '作业中' : '已完成' }}</view>
				<u-button v-if="item.status == 1" type="primary" size="mini" ripple="true" @click="holeSuccecc(item,index,0)">钻孔完成</u-button>
				<u-button v-if="item.status == 0" type="warning" size="mini" ripple="true" @click="holeSuccecc(item,index,1)">继续钻孔</u-button>
			</view>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	import {mapState} from "vuex"
	export default {
		data() {
			return {
				projectID:"",
				curProject:{},
				curHoleData:[]
			}
		},
		onLoad(params) {
			this.projectID = params.projectID;
			this.initData();
		},
		computed:{
			...mapState({
				token:"token"
			})
		},
		methods: {
			async initData(){
				this.$loading("正在加载")
				let res = await this.$network({
					api:"main",
					data:{
						action:"projectAdmin/getProjectDetail",
						data:{id:this.projectID}
					}
				})
				uni.hideLoading()
				if(res.status === 0){
					this.curProject = res.data[0];
					this.curHoleData = this.curProject.holes;
				}
			},
			async holeSuccecc(item,index,s){
				this.$loading("正在修改")
				let {projectID,token} = this;
				let res = await this.$network({
					api:"main",
					data:{
						action:"projectAdmin/updateHoleStatus",
						data:{
							projectID,token,hole:item,status:s
						}
					}
				})
				uni.hideLoading()
				if(res.status === 0){
					this.curHoleData[index].status = s;
					this.$refs.uTips.show({
						title: '修改成功',
						type: 'success'
					})
				} else {
					this.$refs.uTips.show({
						title: '稍后重试',
						type: 'warning'
					})
				}
			}
		}
	}
</script>

<style>
	.lineHeight{
		line-height: 40rpx;
	}
</style>
